import 'dart:ui';

import 'package:flutter/src/services/predictive_back_event.dart';
import 'package:get/get.dart';
import 'package:part_time_job_pro/common/base/base.dart';
import 'package:part_time_job_pro/common/cache/app_box.dart';
import 'package:part_time_job_pro/common/langs/local.dart';
import 'package:part_time_job_pro/common/mixins/user_mixin.dart';
import 'package:part_time_job_pro/common/routers/names.dart';
import 'package:part_time_job_pro/common/utils/common.dart';
import 'package:part_time_job_pro/pages/service/state.dart';
import 'package:flutter/widgets.dart';

class ServiceLogic extends BaseController with UserMixin implements WidgetsBindingObserver {
  final ServiceState state = ServiceState();

  @override
  void onInit() {
    super.onInit();
    WidgetsBinding.instance.addObserver(this);
    getLanguage();
  }

  @override
  onClose() {
    super.onClose();
    WidgetsBinding.instance.removeObserver(this);
  }

  @override
  void didChangeAppLifecycleState(AppLifecycleState state) {
    getLanguage();
  }

  //获取语言
  void getLanguage() {
    switch (AppBox.shared.language) {
      case 0:
        state.languageStr = Local.followerSystemLanguage.tr;
        break;
      case 1:
        state.languageStr = Local.simplifiedChinese.tr;
        break;
      case 2:
        state.languageStr = Local.traditionalChinese.tr;
        break;
      case 3:
        state.languageStr = Local.english.tr;
        break;
      default:
        state.languageStr = Local.followerSystemLanguage.tr;
        break;
    }
    debugPrint('当前语言：${state.languageStr}');
  }

  //切换语言
  void changeLanguage(int index) {
    state.languageIndex.value = index;
    update();
  }

  //切换主题
  void changeTheme(int index) {
    state.themeIndex.value = index;
    update();
  }

  //退出登录
  void loginOut() {
    debugPrint('------退出登录成功 ---------');
    CommonUtil.clearLoginInfo();
    Get.offAllNamed(AppRoutes.userLogin);
  }

  @override
  void didChangeAccessibilityFeatures() {
    // TODO: implement didChangeAccessibilityFeatures
  }

  @override
  void didChangeLocales(List<Locale>? locales) {
    // TODO: implement didChangeLocales
  }

  @override
  void didChangeMetrics() {
    // TODO: implement didChangeMetrics
  }

  @override
  void didChangePlatformBrightness() {
    // TODO: implement didChangePlatformBrightness
  }

  @override
  void didChangeTextScaleFactor() {
    // TODO: implement didChangeTextScaleFactor
  }

  @override
  void didChangeViewFocus(ViewFocusEvent event) {
    // TODO: implement didChangeViewFocus
  }

  @override
  void didHaveMemoryPressure() {
    // TODO: implement didHaveMemoryPressure
  }

  @override
  Future<bool> didPopRoute() {
    // TODO: implement didPopRoute
    throw UnimplementedError();
  }

  @override
  Future<bool> didPushRoute(String route) {
    // TODO: implement didPushRoute
    throw UnimplementedError();
  }

  @override
  Future<bool> didPushRouteInformation(RouteInformation routeInformation) {
    // TODO: implement didPushRouteInformation
    throw UnimplementedError();
  }

  @override
  Future<AppExitResponse> didRequestAppExit() {
    // TODO: implement didRequestAppExit
    throw UnimplementedError();
  }

  @override
  void handleCancelBackGesture() {
    // TODO: implement handleCancelBackGesture
  }

  @override
  void handleCommitBackGesture() {
    // TODO: implement handleCommitBackGesture
  }

  @override
  bool handleStartBackGesture(PredictiveBackEvent backEvent) {
    // TODO: implement handleStartBackGesture
    throw UnimplementedError();
  }

  @override
  void handleUpdateBackGestureProgress(PredictiveBackEvent backEvent) {
    // TODO: implement handleUpdateBackGestureProgress
  }
}
